home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / shells / kiss-0.11 / kiss-0 / kiss / src / listfile.c.orig < prev    next >
Text File  |  1995-03-23  |  2KB  |  76 lines

  1. #include "kiss.h"
  2.  
  3. int listfile (char *name, LsFlags fl)
  4. {
  5.     struct stat
  6.     statbuf;
  7.     char
  8.     buf [FILENAMELEN] = { '\0' },
  9.     tmp [FILENAMELEN];
  10.     struct passwd
  11.     *pwd;
  12.     struct group
  13.     *grp;
  14.     struct tm
  15.     *loctime;
  16.  
  17.     if (lstat (name, &statbuf) && stat (name, &statbuf))
  18.     return (warning ("can't stat \"%s\"", name));
  19.  
  20.     if (fl.longoutput)
  21.     {
  22.     sprintf (buf, "%c%c%c%c%c%c%c%c%c %2d",
  23.          S_IRUSR & statbuf.st_mode ? 'r' : '-',
  24.          S_IWUSR & statbuf.st_mode ? 'w' : '-',
  25.          S_IXUSR & statbuf.st_mode ? 'x' : '-',
  26.          S_IRGRP & statbuf.st_mode ? 'r' : '-',
  27.          S_IWGRP & statbuf.st_mode ? 'w' : '-',
  28.          S_IXGRP & statbuf.st_mode ? 'x' : '-',
  29.          S_IROTH & statbuf.st_mode ? 'r' : '-',
  30.          S_IWOTH & statbuf.st_mode ? 'w' : '-',
  31.          S_IXOTH & statbuf.st_mode ? 'x' : '-',
  32.          (int) statbuf.st_nlink);
  33.  
  34.     if ( (pwd = getpwuid (statbuf.st_uid)) )
  35.         sprintf (tmp, " %9s", pwd->pw_name);
  36.     else
  37.         sprintf (tmp, " %9d", statbuf.st_uid);
  38.     strcat (buf, tmp);
  39.  
  40.     if ( (grp = getgrgid (statbuf.st_gid)) )
  41.         sprintf (tmp, " %9s", grp->gr_name);
  42.     else
  43.         sprintf (tmp, " %9d",statbuf.st_gid);
  44.     strcat (buf, tmp);
  45.  
  46.     sprintf (tmp, " %9ld", (long) statbuf.st_size);
  47.     strcat (buf, tmp);
  48.  
  49.     loctime = localtime (&statbuf.st_mtime);
  50.     sprintf (tmp, " %2.2d/%2.2d/%2.2d %2.2d:%2.2d ",
  51.          loctime->tm_mon, loctime->tm_mday, loctime->tm_year,
  52.          loctime->tm_hour, loctime->tm_min);
  53.     
  54.     strcat (buf, tmp);
  55.     }
  56.  
  57.     strcat (buf, name);
  58.  
  59.     if (fl.listtype)
  60.     {
  61.     if (S_ISDIR (statbuf.st_mode))
  62.         strcat (buf, "/");
  63.     else if (S_ISFIFO (statbuf.st_mode))
  64.         strcat (buf, "=");
  65.     else if (S_ISLNK (statbuf.st_mode))
  66.         strcat (buf, "@");
  67.     }
  68.  
  69.     if (fl.oneperline)
  70.     puts (buf);
  71.     else
  72.     listoutput (buf);
  73.  
  74.     return (0);
  75. }
  76.